from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField


# 文章分类
class Category(models.Model):
    name = models.CharField(max_length=8, verbose_name='类别名称')
    def __str__(self):
        return self.name


# 文章表
class Article(models.Model):
    title = models.CharField(max_length=32, verbose_name='文章标题')
    category = models.ForeignKey('Category', blank=True, null=True, verbose_name='文章类别')
    summary = models.CharField(max_length=256, verbose_name='文章摘要')
    img = models.ImageField(upload_to='img/article', verbose_name='显示图片', default='img/article/IMG_1947.JPG',
                            blank=True)
    create_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    detail = models.OneToOneField('ArticleDetail', verbose_name='文章详情', blank=True, null=True)


# 文章详情表
class ArticleDetail(models.Model):
    content = RichTextUploadingField(verbose_name='文章详情')


# 【学习笔记】、【学员评价】、【入职邀约】
class Feedback(models.Model):
    type_choice = (
        (0, '未分类'),
        (1, '学习笔记'),
        (2, '学员评价'),
        (3, '入职邀约')
    )
    img = models.ImageField(upload_to='img/feedback')
    back_type = models.IntegerField(choices=type_choice, default=0)
